<?php

namespace App\Admin\Controllers;

use App\Admin\Extensions\Grid;
use App\Model\Cms;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid\Filter;
use Encore\Admin\Show;
use Illuminate\Support\Facades\Request;

class CmsController extends AdminController
{

    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '内容管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Cms);

        $grid->column('id', __('Id'));
        $grid->column('title', __('Title'));
        $grid->column('created_at', __('Created at'));
        $grid->column('updated_at', __('Updated at'));

        $grid->filter(function(/** @var Filter $filter */$filter){
            $filter->disableIdFilter();
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Cms::findOrFail($id));

        $show->field('title', __('Title'));
        $show->field('content', __('Content'))->unescape();
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Cms);

        $form->select('category', __('Category'))->options(Cms::$options);
        $form->text('title', __('Title'));
        $form->editor('content', __('Content'));

        return $form;
    }

}
